package com.WGrape.OJ.service.impl;

import com.WGrape.OJ.ai.HuoShanAiManager;
import com.WGrape.OJ.service.ChatService;
import com.volcengine.ark.runtime.model.completion.chat.ChatMessage;
import com.volcengine.ark.runtime.model.completion.chat.ChatMessageRole;

import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author with葡萄成熟时
 * @version 1.0
 */
@Service
public class ChatServiceImpl implements ChatService {

    @Resource
    private HuoShanAiManager huoShanAiManager;

    @Override
    public String doChat(String message) {
        // 系统预设
     String systemPrompt = message;
        final ChatMessage systemMessage = ChatMessage.builder().role(ChatMessageRole.SYSTEM).content(systemPrompt).build();
        List<ChatMessage> messages = new ArrayList<>();
        messages.add(systemMessage);
        // 2. 调用 AI
        String answer = huoShanAiManager.doChat(messages);

        final ChatMessage assistantMessage = ChatMessage.builder().role(ChatMessageRole.ASSISTANT).content(answer).build();
        messages.add(assistantMessage);

        return answer;
    }


}
